<?php
class Bootstrap
    {
    public function __construct($configSection)
    {
        //inkluderer 'library' & 'models' mapperne med i include path'en
        $rootDir = dirname(dirname(__FILE__));
        define('ROOT_DIR', $rootDir);
        set_include_path(get_include_path().PATH_SEPARATOR.ROOT_DIR.'/library/'.PATH_SEPARATOR.ROOT_DIR.'/application/models/');
        
        //enables auto class loading
        require_once 'Zend/Loader/Autoloader.php';
        $loader = Zend_Loader_Autoloader::getInstance();
        
        // Load configuration, stores to registry
        Zend_Registry::set('configSection',$configSection);
        $config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini',$configSection);
        Zend_Registry::set('config', $config);
        
        //sets default time zone from conf. file
        date_default_timezone_set(
        $config->date_default_timezone);
        
        // configure database and store to the registry
        $db = Zend_Db::factory($config->db);
        Zend_Db_Table_Abstract::setDefaultAdapter($db);
        Zend_Registry::set('db', $db);
    }
    
    //sets up front controller
    public function configureFrontController()
    {
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->setControllerDirectory(ROOT_DIR .'/application/controllers');
    }
    
    //runs the application
    public function runApp()
    {
        $this->configureFrontController();
        
        // run!
        $frontController = Zend_Controller_Front::getInstance();
        $frontController->dispatch();
    }
}